package com.my.learn;

import com.lmax.disruptor.RingBuffer;

import java.nio.ByteBuffer;

public class LongEventPrudocer
{
    public  final RingBuffer<LongEvent> ringBuffer;

    public LongEventPrudocer(RingBuffer<LongEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }


    public void onData(ByteBuffer byteBuffer){
        //1，ringbuff 事件队列  下一个槽
        long sequence=ringBuffer.next();
        Long data=null;
        try {
            //2,取出空的事件队列
            LongEvent longEvent=ringBuffer.get(sequence);
            data=byteBuffer.getLong(0);
            longEvent.setValue(data);
            Thread.sleep(50);

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            System.out.println("生产者准备发送数据");
            ringBuffer.publish(sequence);
        }
    }
}
